package com.ruoyi.develop.goodsInvoiceSelf.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;

import javax.annotation.Resource;

import com.ruoyi.develop.goodsFee.domain.GoodsFee;
import org.springframework.stereotype.Service;
import com.ruoyi.develop.goodsInvoiceSelf.mapper.GoodsInvoiceSelfMapper;
import com.ruoyi.develop.goodsInvoiceSelf.domain.GoodsInvoiceSelf;
import com.ruoyi.develop.goodsInvoiceSelf.service.IGoodsInvoiceSelfService;

/**
 * 个人发票信息管理Service业务层处理
 *
 * @author qh
 * @date 2023-01-12
 */
@Service
public class GoodsInvoiceSelfServiceImpl implements IGoodsInvoiceSelfService {
    @Resource
    private GoodsInvoiceSelfMapper goodsInvoiceSelfMapper;

    /**
     * 查询个人发票信息管理
     *
     * @param id 个人发票信息管理主键
     * @return 个人发票信息管理
     */
    @Override
    public GoodsInvoiceSelf selectById(String id) {
        return goodsInvoiceSelfMapper.selectById(id);
    }

    /**
     * 查询个人发票信息管理列表
     *
     * @param entity 个人发票信息管理
     * @return 个人发票信息管理
     */
    @Override
    public List<GoodsInvoiceSelf> selectList(GoodsInvoiceSelf entity) {
        return goodsInvoiceSelfMapper.selectList(entity);
    }

    /**
     * 新增个人发票信息管理
     *
     * @param entity 个人发票信息管理
     * @return 结果
     */
    @Override
    public int insert(GoodsInvoiceSelf entity) {
        if (StringUtils.isBlank(entity.getId())) {
            entity.setId(IdUtils.fastSimpleUUID());
        }
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        return goodsInvoiceSelfMapper.insert(entity);
    }

    /**
     * 修改个人发票信息管理
     *
     * @param entity 个人发票信息管理
     * @return 结果
     */
    @Override
    public int update(GoodsInvoiceSelf entity) {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return goodsInvoiceSelfMapper.update(entity);
    }

    /**
     * 批量删除个人发票信息管理
     *
     * @param ids 需要删除的个人发票信息管理主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String[] ids) {
        return goodsInvoiceSelfMapper.deleteByIds(ids);
    }

    /**
     * 删除个人发票信息管理信息
     *
     * @param id 个人发票信息管理主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return goodsInvoiceSelfMapper.deleteById(id);
    }

    @Override
    public void createInvoiceByFee(GoodsFee fee) {
        GoodsInvoiceSelf param = new GoodsInvoiceSelf();
        param.setTaxNo(fee.getInvoiceNo());
        List<GoodsInvoiceSelf> selfList = selectList(param);
        if (selfList.isEmpty()) {
            param.setTaxInfo(fee.getName());
            param.setTaxDate(new Date());
            param.setImburseDate(new Date());
            param.setTaxMoney(fee.getMoney());
            param.setUserId(SecurityUtils.getUserId());
            param.setUserName(SecurityUtils.getNickName());
            insert(param);
        }
    }


}
